<template>
<div class="con_box">
    <!-- 搜索栏目开始 -->
    <div class="search_column">
        <el-form ref="searchForm" :inline="true" :model="table.queryParams" label-width="95px" size="mini">
            <el-form-item label="用户名：">
                <el-input v-model="table.queryParams.keyWord"></el-input>
            </el-form-item>

            <el-form-item label="">
                <el-button type="primary" size="small" icon="el-icon-search" @click="searchSubmit">查 询</el-button>
                <el-button type="primary" size="small" icon="el-icon-refresh" @click="resetSubmit(table.queryParams)">重 置</el-button>
            </el-form-item>
        </el-form>
    </div>
    <!-- 搜索栏目结束 -->
    <!-- 操作栏开始 -->
    <div class="btns_column clearfix">
        <div class="fl">
            <el-button type="primary" size="mini" icon="el-icon-plus" @click="toFilmsAdd">添加底片</el-button>
        </div>
        <div class="fr">
           <!--  <a v-has="'student:import'" href="javascript:void(0)" @click="downloadTemplate" class="link_txt">
                下载导入模板
            </a> -->
        </div>
    </div>
    <!-- 操作栏结束 -->
	<vue-table
	    :api-url="table.apiUrl"
	    :fields="table.fields"
	    :appendParams="table.queryParams"
	    :content="self"
	    ref="dictionaryTable">
	</vue-table>
    <films-add ref="filmsAdd"></films-add>
</div>
</template>
<script>
    import films_add from "./films_add"
    import moment from 'moment'
	export default {
		components:{
          "films-add":films_add,
        },
		data() {
			return {
                self:this,
				table: {
                    apiUrl: api.filmsManagement.filmsList,
                    queryParams: {
                        type:''
                    },
                    fields: [{
                            prop: "__index",
                            width: "60",
                            label: "序号",
                        },
                        {
                            prop: "name",
                            label: "底片名称",
                        },
                        {
                            prop: "url",
                            label: "底片地址",
                        },
                        {
                            prop: "created",
                            label: "时间",
                            formatter : function(row, column, cellValue){                                
                                if(cellValue){
                                    if(cellValue){
                                        return moment(cellValue).format('YYYY-MM-DD')
                                    }
                                }
                            }
                        },
                        {
                            prop: "__action",
                            label: "操作",
                            width:100,
                            actions: [

                                {
                                    label: "编辑",
                                    type: "edit",
                                    func: function(vm, row) {
                                        vm.$refs.filmsAdd.showDialog(row);
                                    }
                                },
                                {
                                    label: "删除",
                                    type: "delete",
                                    func: function(vm, row) {
                                        vm.deleteDictionary(row.id);
                                    }
                                }
                            ]
                        }

                    ],
                },
			}
		},
		methods: {
            // 查询
            searchSubmit(){
                this.$refs.dictionaryTable.$emit('vuetable:refresh');
            },
            //重置
            resetSubmit(val){
                for(var key in val){
                    val[key] = '';
                }
                this.$refs.dictionaryTable.$emit('vuetable:refresh');
            },
            // 添加底片
            toFilmsAdd(){
                this.$refs.filmsAdd.showDialog();
            },
            deleteDictionary(id){
                let vm = this;
                vm.$confirm('是否删除该条记录！', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                })
                .then(() => {
                    vm.axios.delete(api.filmsManagement.filmsList+'/'+id)
                    .then((response) => {
                        if(response.data.success){
                            vm.$message.success(response.data.message);
                            vm.$refs.dictionaryTable.$emit('vuetable:current-refresh');
                        }else{
                            vm.$message.error(response.data.message);
                        }
                    });
                },()=>{})
            }
        },
		mounted() {
        }
	}
</script>